import aip
# from xlrd import open_workbook  #用来读取excel
import xlrd
import numpy as np
import pandas as pd
import time
from tqdm import tqdm  # 查看进度条
import emojiswitch
# 引用库
from langdetect import detect
from langdetect import detect_langs
from translate import Translator

# 当文本过短或模糊时，判断出来的结果会不确定；
# 如果要让结果唯一，添加以下两行：
from langdetect import DetectorFactory

DetectorFactory.seed = 0

# 整个思路就是：1、将文件内容批量读取，并处理完成后输出到文件2、进度条展示 3、使用pandas处理数据文件
content_list = []
positive_prob_list = []
negative_prob_list = []


def sentiment_classify(txt):
    global results
    client_appid = '31384493'
    client_ak = 'H8N5o5kINuUyjjQkeLhtH8Qm'
    client_sk = 'rXQiQg9MeASl11bmyZAQLGZMz3YhSptu'
    my_nlp = aip.nlp.AipNlp(client_appid, client_ak, client_sk)
    results = my_nlp.sentimentClassify(txt)
    positive_prob = results['items'][0]['positive_prob']
    negative_prob = results['items'][0]['negative_prob']
    content_list.append(txt)
    positive_prob_list.append(positive_prob)
    negative_prob_list.append(negative_prob)
    return my_nlp.sentimentClassify(txt)['items'][0]['positive_prob']


# print(sentiment_classify("我真的生气了"))
# data = pd.read_csv("D:\\评论.csv")
# work_book=xlrd.open_workbook("C:\\Users\Administrator\Desktop\pinglun.xls")  #打开文件
# sheet_name = work_book.sheet_names()  #打印所有sheet名称，是个列表
# print(sheet_name)
# print(data)
